using System;
using System.Collections.Generic;
using System.Text;

namespace RapidHDL
{
    public class FPGABlock
    {
        Dictionary<int, FPGAEntry> dicEntries = new Dictionary<int, FPGAEntry>();

        public void Reset()
        {
            dicEntries.Clear();
        }

        public void AddEntry(int piAddress, int piRoute, uint piData, bool pbWriteBit)
        {
            FPGAEntry oEntry = new FPGAEntry();
            oEntry.Address = piAddress;
            oEntry.Route = piRoute;
            oEntry.Data = piData;
            oEntry.WriteBit = pbWriteBit;
            dicEntries.Add(dicEntries.Count, oEntry);
        }

        public void Submit(int piValue)
        {
            AddEntry(1,1,(uint)piValue,true);
        }

        public void LoadA(int piValue)
        {
            AddEntry(1, 2, (uint)piValue, true);
        }

        public void LoadB(int piValue)
        {
            AddEntry(1, 3, (uint)piValue, true);
        }

        public void WriteProgRAM(int piAddress)
        {
            AddEntry(1, 60, (uint)piAddress,true);
        }

        public Dictionary<int, Dictionary<int, FPGAEntry>>  Split()
        {
            Dictionary<int, Dictionary<int, FPGAEntry>>  dicSplit = new Dictionary<int, Dictionary<int, FPGAEntry>>();
            int iBlock = 0;
            Dictionary<int, FPGAEntry> dicBlock = new Dictionary<int,FPGAEntry>();
            foreach (int iEntry in dicEntries.Keys)
            {
                if (dicBlock.Count == 2)
                {
                    dicSplit.Add(dicSplit.Count, dicBlock);
                    dicBlock = new Dictionary<int, FPGAEntry>();
                }
                dicBlock.Add(dicBlock.Count, dicEntries[iEntry]);
            }
            if (dicBlock.Count > 0)
                dicSplit.Add(dicSplit.Count, dicBlock);
            return dicSplit;
        }
    }
}
